#ifndef ROBOTCONTROLLER_H
#define ROBOTCONTROLLER_H

// Include files.
#include <set>
#include "../Subscriber.hpp"

class SystematicRobot;

/**
 *  The Service class controls robot subsystems and other Services.
 *  
 *  A Service broadly represents a will to do something. (e.g. A DriveService would represent the will to drive the robot.)
 *  
 *  To use it, create subclasses that override HandleStart, HandleStop, and HandlePeriodic.
 *  Remember that they will only run if they have been started by the Start function.
 *  
 *  All Services must be added to the SystematicRobot or to a Service already added to the robot.
 *  A service can be added to the robot in such a way as to run when the robot is in a certain state (e.g. Autonomous, Teleop).
 *  They will be started at the correct time, and can start other Services as needed.
 *  
 *  Testing shows this class works.
 */
class Service :
	public Subscriber
{
	// Befriend our robot class so it can call our functions.
	friend class SystematicRobot;
	
	// For efficiency, CompoundController uses RobotControllers own m_subcontrollers to store compounded controllers.
	friend class CompoundService;
	
	// HACK: We should better integrate state machine States into the Systematic framework.
	friend class StateMachineService;
	
	public:
		Service();
		virtual ~Service();
		bool GetIsStarted() const;
		void Start();
		void Stop();
	protected:
		Service &AddSubservice(Service &service);
		virtual void HandleStart();
		virtual void HandleStop();
		virtual void HandlePeriodic();
	private:
		bool m_isStarted;
		std::set<Service*> m_subservices;
};

#endif // #ifndef ROBOTCONTROLLER_H 
